import i18n from '@root/i18n'

world.onPlayerJoin(async ({ entity }) => {
    entity.k1 = 0
    entity.k2 = 0
    entity.k3 = 0
    entity.k4 = 0
    entity.key = 0
    entity.indoor = 1
})



// const mw = world.querySelector('#木屋钥匙')
// mw.enableInteract = true
// mw.interactRadius = 3
// mw.interactHint = `拾取（木屋钥匙）`
// mw.onInteract(async({entity}) => {
//     entity.player.directMessage(`你获得了木屋钥匙，现在开始，你可以进入木屋了`)
//     entity.bq.push('进入木屋')
//     entity.addTag('木屋')
// })

const key_safe = world.querySelector('#安全钥匙')
if (key_safe) {
    key_safe.enableInteract = true
    key_safe.interactRadius = 3
    key_safe.interactHint = `拾起（安全钥匙） Pick up (Safe Key)`
    key_safe.onInteract(async ({ entity }) => {
        entity.addTag('安全钥匙')
        entity.bq.push(i18n.t("safe_key_message", { lng: entity.player.language }))
        entity.player.directMessage(i18n.t("safe_key_message", { lng: entity.player.language }))
    })
}
const key_1 = world.querySelector('#电闸-1')
if (key_1) {
    key_1.enableInteract = true
    key_1.interactRadius = 3
    key_1.interactHint = `拉动 Pull`
    key_1.onInteract(async ({ entity }) => {
        if (entity.key < 4) {
            if (entity.k1 == 0) {
                entity.key += 1
                entity.k1 = 1
                entity.player.directMessage(i18n.t("switch_message", { lng: entity.player.language, count: entity.key }))
            }
        }
    })
}
const key_2 = world.querySelector('#电闸-2')
if (key_2) {
    key_2.enableInteract = true
    key_2.interactRadius = 3
    key_2.interactHint = `拉动 Pull`
    key_2.onInteract(async ({ entity }) => {
        if (entity.key < 4) {
            if (entity.k2 == 0) {
                entity.key += 1
                entity.k2 = 1
                entity.player.directMessage(i18n.t("switch_message", { lng: entity.player.language, count: entity.key }))
            }
        }
    })
}
const key_3 = world.querySelector('#电闸-3')
if (key_3) {
    key_3.enableInteract = true
    key_3.interactRadius = 3
    key_3.interactHint = `拉动 Pull`
    key_3.onInteract(async ({ entity }) => {
        if (entity.key < 4) {
            if (entity.k3 == 0) {
                entity.key += 1
                entity.k3 = 1
                entity.player.directMessage(i18n.t("switch_message", { lng: entity.player.language, count: entity.key }))
            }
        }
    })
}
const key_4 = world.querySelector('#电闸-4')
if (key_4) {
    key_4.enableInteract = true
    key_4.interactRadius = 3
    key_4.interactHint = `拉动 Pull`
    key_4.onInteract(async ({ entity }) => {
        if (entity.key < 4) {
            if (entity.k4 == 0) {
                entity.key += 1
                entity.k4 = 1
                entity.player.directMessage(i18n.t("switch_message", { lng: entity.player.language, count: entity.key }))
            }
        }
    })
}

// const mw = world.querySelector('#木屋钥匙')
// mw.enableInteract = true
// mw.interactRadius = 3
// mw.interactHint = `拾取（木屋钥匙）`
// mw.onInteract(async({entity}) => {
//     entity.player.directMessage(`你获得了木屋钥匙，现在开始，你可以进入木屋了`)
//     entity.addTag('木屋')
// })


const qc = world.querySelector('#跑车钥匙-1')
if (qc) {
    qc.enableInteract = true
    qc.interactRadius = 3
    qc.interactHint = `拾取（汽车钥匙） Pick up (Car Key)`
    qc.onInteract(async ({ entity }) => {
        entity.player.directMessage(i18n.t("car_key_message", { lng: entity.player.language }))
        entity.addTag('汽车')
        entity.bq.push(i18n.t("car_key_message", { lng: entity.player.language }))
    })
}
